package com.medicine.hbp.http;

import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpConfig;
import org.kymjs.kjframe.http.HttpParams;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.medicine.hbp.R;
import com.medicine.hbp.sp.LoginSp;
import com.medicine.hbp.uitl.CommUtil;
import com.medicine.hbp.uitl.MD5;
import com.medicine.hbp.uitl.MyApplication;

public class AppHttps {
//	public static final String HTTP_URL = "http://"+MyApplication.getMyApplication().getIp()+"/api/";//医疗app
	public static final String HTTP_URL = "http://yil.micro120.com/api/";//医疗app
	public static final String APP_ID = "89317976";//医疗app id
//
//	public static final String APP_ID = "78376904";//美容app id
//	public static final String HTTP_URL = "http://mr.micro120.com/api/";//美容app

	private static  final KJHttp http=new KJHttp();
	private static  final HttpConfig config=new HttpConfig();
	private static String datas;
	private static String seq;
	/**
	 * @param suffix 接口名
	 * @param params 参数集合
	 * @param callback  回调方法
	 */
	@SuppressWarnings("deprecation")
	public static void HttpPost(Context activity,String suffix, HttpParams params, HttpCallBack callback) {
		datas=MD5.getData();
		seq=MD5.getSeq(activity.getResources().getString(R.string.app_id), datas);
		params.putHeaders("authNameId", activity.getResources().getString(R.string.app_id));//所属应用ID
//		seq=MD5.getSeq(APP_ID, datas);
//		params.putHeaders("authNameId",APP_ID);//所属应用ID

		params.putHeaders("appType", "Android");
		params.putHeaders("datetime",datas);//当前时间long的值
		params.putHeaders("seq", seq);
		params.putHeaders("platformPwd", MD5.getMD5String(seq+"A956B2EEDB"));//当前时间long的值
		if(!TextUtils.isEmpty(LoginSp.getToken(activity))){
			params.put("token", LoginSp.getToken(activity));
		}
		params.put("userToken",  CommUtil.getIMEI(activity));
		config.cacheTime=0;
		config.TIMEOUT=100000;
		if(!TextUtils.isEmpty(MyApplication.getMyApplication().getCookitString())){
			config.setCookieString(MyApplication.getMyApplication().getCookitString());
			Log.e("Cookit", MyApplication.getMyApplication().getCookitString());
		}
		http.setConfig(config);
		http.post(HTTP_URL + suffix, params, false,callback);
		if(CommUtil.isLog){
			Log.e("访问地址：", HTTP_URL + suffix);
			Log.e("请求参数：", params.getUrlParams().toString());
		}
	}
//	public static void HttpGet(String suffix, HttpParams params, HttpCallBack callback) {
////		http= new KJHttp();
//		http.get(HTTP_URL + suffix, params, callback);
//	}
}
